<template>
	<view class="container">
		<view class="user-section">
			<image class="bg" src="/static/bg_recharge.png"></image>
			<view class="user-info-box">
				<view class="member-top-c">
					<template>
						<image class='portrait' mode="aspectFill" :src='userDetailInfo.icon'></image>
						<view class='user-name' style="text-align: center;font-size: 30rpx;">
							{{ userDetailInfo.nickname }}
						</view>
					</template>
					<view class="yue">
						<text>当前门店余额：{{integral/100}}</text>
					</view>
				</view>
			</view>
		</view>
		<view>
			<view class="title">
				<view class="titleleft"></view>
				<view class="titletxt">
					<text>请选择充值套餐</text>
				</view>
			</view>
			<view class="rechargemeal">
				<view :class="panduan==index ? 'meal-item-selected':'meal-item' " v-for="(item, index) in meals"
					:key="index" @click="changePrice(item,$event,index)">
					<text class="t1">充值</text>
					<text class="t2">{{item.price}}元</text>
					<text class="t3">送{{item.giveMoney}}元</text>
					<view class="tag" v-if="item.isHot==0">
						<text>推荐</text>
					</view>
				</view>
			</view>
			<view class="cut"></view>
			<view class="title">
				<view class="titleleft"></view>
				<view class="titletxt">
					<text>充值提示</text>
				</view>
			</view>
			<view style="padding-left: 31rpx;padding-top: 39rpx;padding-bottom: 180rpx;">
				<text class="tishi">1、充值余额永久有效,不支持退款</text></br>
				<text class="tishi">2、充值余额可用于门店预约、订单续单</text></br>
				<text class="tishi">3、充值余额仅限指定门店使用</text><text style="margin-left: 10rpx;color: #75C684;">{{store.name}}</text></br>
				<text class="tishi">4、充值如果发生任何异常、问题请联系商家</text></br>
				<text class="call">联系电话:</text>
				<text class="phonenumber" @click="call(store.servicePhone)">{{store.servicePhone}}</text>
			</view>
			<uni-popup ref="tishi" :mask-click="true" type="center">
				<view class="unipopup">
					<image src="/static/notice.png"></image>
					<view class="successtxt">
						<text style="font-size: 32rpx;padding-left: 100rpx;">可适用的门店:</text>
					</view>
					<view class="successtxt">
						<text>{{store.name}}</text>
					</view>
					<view class="buttomafrim" @click="closeTishi()"><text>我已知晓</text></view>
				</view>
			</uni-popup>
		</view>
		<view class="button">
			<!-- <button @click="generateOrder()" style="width: 700rpx;background-color: #127202;color: white;">
				<text>充值{{youhui}}</text>
			</button> -->
			<image src="../../static/bg_recharge_button.png"></image>
			<view v-if="panduan!=999" class="rechargesub">
				<text
					style="font-size: 30rpx;font-family: Source Han Sans CN;font-weight: 400;color: #FFF1D0;">充值</text>
				<text style="font-size: 28rpx;font-family: Source Han Sans CN;font-weight: 400;color: #75C684;">￥</text>
				<text
					style="font-size: 48rpx;font-family: ProductSans;font-weight: bold;color: #75C684;">{{price}}</text>
				<text
					style="font-size: 24rpx;font-family: Source Han Sans CN;font-weight: 400;color: #FFF1D0;">得{{price+giveMoney}}</text>
			</view>
			<view class="rechargesub1" @click="generateOrder()">
				<text
					style="font-size: 32rpx;font-family: Source Han Sans CN;font-weight: 500;color: #FEFEFE;">确认并支付</text>
			</view>
		</view>
	</view>
</template>
<script>
	import Api from '@/common/api';
	import listCell from '@/components/mix-list-cell';
	import {
		mapState
	} from 'vuex';
	import store from '../../store';
	export default {
		components: {
			listCell
		},
		data() {
			return {
				userDetailInfo: {},
				currentCoachId: null,
				role: '0', //0:学员 1:教练
				meals: [],
				desc: '',
				panduan: 0,
				price: 0,
				rechargeMealId: null,
				storeId: null,
				giveMoney: 0,
				integral: 0,
				youhui: '',
				store: null
			};
		},
		async onShow() {},
		async onLoad(options) {
			console.log("onLoad========" + this.hasLogin);
			if (this.hasLogin) {
				let username = this.userInfo.userInfo.username;
				let params = {
					memberId: this.userInfo.userInfo.id
				};
				let data1 = await Api.apiCall('get', Api.index.userInfo, params);
				console.log(data1);
				this.userDetailInfo = data1.member;
				this.currentCoachId = this.userInfo.userInfo.coachId;
				this.getIntegral(this.userInfo.userInfo.id, options.storeId);
			}
			this.storeId = options.storeId;
			this.getStoreById(options.storeId);
			this.getRechargeMeal(options.storeId);
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			selectStore() {
				this.$refs.tishi.open('center')
			},
			closeTishi() {
				this.$refs.tishi.close()
			},
			call(mobile) {
				if (typeof(mobile) == 'undefined' || mobile == '') {

				} else {
					uni.makePhoneCall({
						phoneNumber: mobile,
						success: function() {
							console.log('拨打电话成功');
						},
						fail() {
							console.log('打电话失败了');
						}
					})
				}
			},
			async getIntegral(memberId, storeId) {
				let params = {
					memberId: memberId,
					storeId: storeId
				}
				let data = await Api.apiCall('get', Api.qsg.getIntegral, params);
				if (data) {
					this.integral = data.integral
				}
			},
			async getStoreById(storeId) {
				let data = await Api.apiCall('get', Api.store.getStoreById, {
					storeId: storeId
				});
				if (data) {
					this.store = data
				}
			},
			toBuyVip() {
				uni.navigateTo({
					url: '/pages/user/vip/buyvip?pushId=0'
				});
			},
			async changePrice(item, e, index) {
				this.panduan = index;
				this.desc = item.name;
				this.price = item.price;
				this.rechargeMealId = item.id;
				this.giveMoney = item.giveMoney;
				this.youhui = this.price + '送' + this.giveMoney
			},
			async getRechargeMeal(storeId) {
				let params = {
					storeId: storeId
				};
				let data = await Api.apiCall('get', Api.qsg.getRechargeMeal, params);
				if (data) {
					console.log(data)
					this.meals = data;
					this.price = this.meals[0].price;
					this.desc = this.meals[0].name;
					this.giveMoney = this.meals[0].giveMoney
					this.rechargeMealId = this.meals[0].id
				}
			},
			async generateOrder() {
				let that = this;
				if (null == that.rechargeMealId) {
					uni.showToast({
						icon: 'none',
						title: '请选择充值套餐'
					})
					return false;
				}
				let params = {
					rechargeMealId: that.rechargeMealId,
					storeId: that.storeId,
					mealName: that.desc,
					price: that.price,
					giveMoney: that.giveMoney
				};
				let data = await Api.apiCall('post', Api.order.createRechargeOrder, params);
				console.log(data);
				if (data) {
					let id = data.id;
					let price = this.price;
					let realprice = price + this.giveMoney;
					let storeId = this.storeId;
					let url =
						`/pages/money/rechargepay?id=${id}&price=${price}&realprice=${realprice}&storeId=${storeId}`;
					uni.redirectTo({
						url: url
					});
				} else {
					that.$core.msg(data);
				}
			},
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.navigateTo({
					url: url
				});
			},
			switchTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.switchTab({
					url: url
				});
			},
			rediTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.redirectTo({
					url: url
				});
			},
			toLogin() {
				uni.redirectTo({
					url: '/pages/public/login'
				});
			}
		}
	};
</script>
<style lang="scss">
	.rechargesub {
		position: absolute;
		top: -5rpx;
		left: 30rpx;
	}

	.rechargesub1 {
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #FEFEFE;
		position: absolute;
		top: 15rpx;
		left: 460rpx;
	}

	.user-remainder {
		font-size: 26rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 1.8;
	}

	.member-top-c {
		margin: 0 auto;
		margin-top: 90rpx;
	}

	.user-name {
		line-height: 1;
		font-size: 36rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #FFFFFF;
	}

	%flex-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.yue {
		width: auto;
		height: 48rpx;
		background: #3D9B64;
		border-radius: 24rpx;
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #A9DAB9;
		padding: 5rpx;
		margin-top: 25rpx;
		padding-left: 10rpx;
		padding-right: 10rpx;
	}

	%section {
		display: flex;
		justify-content: space-around;
		align-content: center;
		background: #fff;
		border-radius: 10upx;
	}

	.user-section {

		height: 410rpx;
		position: relative;
		box-sizing: border-box;
		padding: 55rpx 30upx;

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
		}
	}

	.titleleft {
		width: 4rpx;
		height: 28rpx;
		background: #0DA944;
		border-radius: 2rpx;
	}

	.retailtit {
		width: 100%;
		height: 60upx;
		line-height: 40upx;
		font-size: 32upx;
		font-weight: bold;
		color: #333;
	}

	.retaillist {
		display: flex;
		width: 100%;
		border-bottom: 1upx solid #f6f6f6;
		text-align: center;
		padding-bottom: 20upx;
		margin-bottom: 20upx;
	}

	.retaillist:last-child {
		padding-bottom: 0;
		margin-bottom: 0;
		border-bottom: none;
	}

	.retaileach {
		flex: 1;
	}

	.title {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #1A1A1A;
		display: flex;
		margin-top: 33rpx;
		margin-left: 32rpx;
	}

	.titletxt {
		height: 28rpx;
		line-height: 28rpx;
		margin-left: 16rpx;
	}

	.retailtxt {
		font-size: 26upx;
		color: #949494;
		line-height: 50upx;
	}

	.retailname {
		font-size: 36upx;
		color: #e61a0f;
		font-weight: bold;
	}

	.call {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #555555;
		padding-left: 40rpx;
	}

	.rechargemeal {
		height: auto;
		display: flex;
		flex-wrap: wrap;
		padding-left: 31rpx;
		padding-top: 34rpx;
	}

	.retailtitle {
		font-size: 30upx;
		color: #333;
	}

	.user-info-box {
		height: 190upx;
		display: flex;
		align-items: center;
		position: relative;
		z-index: 1;
		margin: 0 auto;

		.portrait {
			width: 140upx;
			height: 140upx;
			border: 5upx solid #fff;
			border-radius: 50%;
			margin: 0 auto 20upx;
			display: block;

			image {
				width: 130upx;
				height: 130upx;
				border-radius: 50%;
			}
		}

		.username {
			font-size: $font-lg + 6upx;
			color: $font-color-dark;
			margin-left: 20upx;
		}
	}

	.login-btn {
		color: #333;
		width: 180upx;
		height: 50upx;
		line-height: 50upx;
		border-radius: 25upx;
		background: #ffffff;
		font-size: 12px;
	}

	.tishi {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #666666;
	}

	.button {
		z-index: 1;
		height: 100rpx;
		// margin-top: 80rpx;
		margin-left: 32rpx;
		position: relative;
		position: fixed;
		bottom: calc(100% - 99%);

		image {
			height: 88rpx;
			width: 686rpx;
		}
	}

	.tag {
		width: 68rpx;
		height: 36rpx;
		background: linear-gradient(-45deg, #343230, #695844);
		border-radius: 16rpx 0rpx 16rpx 0rpx;
		font-size: 20rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFF7D6;
		position: absolute;
		left: 0;
		top: 0;
		line-height: 36rpx;
		text-align: center;
	}

	.vip-card-box {
		display: flex;
		flex-direction: column;
		color: #f7d680;
		height: 240upx;
		background: linear-gradient(left, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.8));
		border-radius: 16upx 16upx 0 0;
		overflow: hidden;
		position: relative;
		padding: 20upx 24upx;

		.card-bg {
			position: absolute;
			top: 20upx;
			right: 0;
			width: 380upx;
			height: 260upx;
		}

		.b-btn {
			position: absolute;
			right: 20upx;
			top: 16upx;
			width: 132upx;
			height: 40upx;
			text-align: center;
			line-height: 40upx;
			font-size: 22upx;
			color: #36343c;
			border-radius: 20px;
			background: linear-gradient(left, #f9e6af, #ffd465);
			z-index: 1;
		}

		.tit {
			font-size: $font-base + 2upx;
			color: #f7d680;
			margin-bottom: 28upx;

			.yticon {
				color: #f6e5a3;
				margin-right: 16upx;
			}
		}

		.e-b {
			font-size: $font-sm;
			color: #d8cba9;
			margin-top: 10upx;
		}
	}

	.phonenumber {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 600;
		color: #555555;
	}

	.cover-container {
		background: $page-color-base;
		padding: 30upx 30upx;
		position: relative;
		background: #f5f5f5;

		.arc {
			position: absolute;
			left: 0;
			top: -34upx;
			width: 100%;
			height: 36upx;
		}
	}

	.tj-sction {
		@extend %section;

		.tj-item {
			@extend %flex-center;
			flex-direction: column;
			height: 140upx;
			font-size: $font-sm;
			color: #75787d;
		}

		.num {
			font-size: $font-lg;
			color: $font-color-dark;
			margin-bottom: 8upx;
		}
	}

	.order-section {
		@extend %section;
		padding: 28upx 0;
		margin-top: 20upx;

		.order-item {
			@extend %flex-center;
			width: 120upx;
			height: 120upx;
			border-radius: 10upx;
			font-size: $font-sm;
			color: $font-color-dark;
		}

		.yticon {
			font-size: 48upx;
			margin-bottom: 18upx;
			color: #e61a0f;
		}

		.icon-shouhoutuikuan {
			font-size: 44upx;
		}
	}

	.history-section {
		background: #fff;
		border-radius: 10upx;

		.sec-header {
			display: flex;
			align-items: center;
			font-size: $font-base;
			color: $font-color-dark;
			line-height: 40upx;
			margin-left: 30upx;

			.yticon {
				font-size: 44upx;
				color: #5eba8f;
				margin-right: 16upx;
				line-height: 40upx;
			}
		}

		.h-list {
			white-space: nowrap;
			padding: 30upx 30upx 0;

			image {
				display: inline-block;
				width: 160upx;
				height: 160upx;
				margin-right: 20upx;
				border-radius: 10upx;
			}
		}
	}

	.meal-item {
		position: relative;
		width: 218rpx;
		height: 200rpx;
		background: #F7F7F7;
		border: 2px solid #E8E8E8;
		border-radius: 24rpx;
		margin-right: 17rpx;
		margin-bottom: 16rpx;
		flex-direction: column;
		display: flex;
		justify-content: center;
		align-items: center;

		.t1 {
			font-size: 24rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #5A595C;
		}

		.t2 {
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 600;
			color: #1A1A1A;
		}

		.t3 {
			font-size: 24rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #666666;
		}
	}

	.cut {
		background-color: #F7F7F7;
		height: 20rpx;
	}

	.contact-content {
		background: #f5f5f5;
		margin-top: 20rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
	}

	.meal-item-selected {
		position: relative;
		width: 218rpx;
		height: 200rpx;
		background: #FEFAF1;
		border: 2px solid #E3A66D;
		border-radius: 24rpx;
		margin-right: 17rpx;
		margin-bottom: 16rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;

		.t1 {
			font-size: 24rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #5A595C;
		}

		.t2 {
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 600;
			color: #EA4A33;
		}

		.t3 {
			font-size: 24rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #EA4A33;
		}
	}

	.meal-content {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		text-align: center;
		padding: 30rpx;
	}

	.unipopup {
		height: 540rpx;
		width: 460rpx;
		background-color: #FFFFFF;
		border-radius: 24rpx;
		position: relative;
		image {
			width:100%;
			height: 120rpx;
			border-top-left-radius: 24rpx;
			border-top-right-radius: 24rpx;
		}
	}

	.successtxt {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 600;
		letter-spacing: 1rpx;
		color: #424242;
		margin-left: 20rpx;
	}

	.welcome {
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #9A9A9A;
	}

	.buttomafrim {
		width: 200rpx;
		height: 80rpx;
		background: #0DA944;
		border-radius: 40rpx;
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 80rpx;
		text-align: center;
		margin-left: 126rpx;
		position: absolute;
		bottom:25rpx;
		
	}
</style>